﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MetaTracker.ViewModel;
using System.Threading.Tasks;

namespace MetaTracker.View
{
    /// <summary>
    /// Interaction logic for AddUserWindow.xaml
    /// </summary>
    public partial class AddUserWindow : Window
    {
        public AddUserWindow()
        {
            InitializeComponent();

            if (DataContext == null || !(DataContext is AddUserViewModel))
            {
                DataContext = new AddUserViewModel();
            }

            RegisterButton.Click += new RoutedEventHandler(RegisterButton_Click);
        }

        void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            bool success = 
                (DataContext as AddUserViewModel).Register(PasswordBox1.SecurePassword, PasswordBox2.SecurePassword);

            if (success)
            {
                MessageBox.Show(string.Format("User {0} has been registered", 
                    (DataContext as AddUserViewModel).NewUserName), "Success!", MessageBoxButton.OK);
                this.Close();
            }
        }
    }
}
